#!/bin/sh
#抽取日表数据到dws_urea_abnormal_pdi表中
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE-$0}")"; pwd)
UP_DIR=$(dirname $(dirname $(dirname "$PWD")))
echo ${UP_DIR}
source ${UP_DIR}/system_env.sh


START_TIME=$(date +%s)
hive_db=${hive_db}

if [ -z "${hive_db}" ];then
  hive_db=dataplatform_trip
else
  hive_db=${hive_db}
fi


if [ -z "$1" ];then
  part_time=$(date -d "1 days ago" +%Y%m%d)
else
  part_time=$1
fi

sql_suffix=$(cat <<EOF
  insert into table ${hive_db}.dws_urea_abnormal_pdi partition(day)
  select tid,extend_field09,extend_field07,extend_field08,extend_field06,extend_field05,day from ${hive_db}.trip_events where day = ${part_time} and event = 'ureaAbnormal';

EOF
)

CUR_DIR=$(cd "$(dirname "$0")"; pwd)
hive_config=$(cat  "${CUR_DIR}"/hive.config)
sql="${hive_config}${sql_suffix}"
echo "导入dws_urea_abnormal_pdi的SQL为：${sql}"

#执行语句·
hive -e "${sql}"
if [ $? -ne 0 ];then
  echo "导入dws_urea_abnormal_pdi失败，耗时$((`date +%s`-START_TIME))秒..."
else
  echo "导入dws_urea_abnormal_pdi成功，耗时$((`date +%s`-START_TIME))秒..."
fi